package com.zx.user.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zx.user.config.NacosStorageProperty;
import com.zx.user.entity.Storage;
import com.zx.user.mapper.StorageMapper;
import com.zx.user.service.StorageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.context.refresh.ContextRefresher;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author 虎哥
 */
@Slf4j
@Service
@RefreshScope
public class StorageServiceImpl extends ServiceImpl<StorageMapper, Storage> implements StorageService {

    @Autowired
    private StorageMapper storageMapper;

    @Resource

    // @NacosValue(value = "${szh.name}",autoRefreshed = true)
    @Autowired
    private NacosStorageProperty nacosStorageProperty;

    
    @Override
    public String nacosDyValue() {
        log.error("namce->{}",nacosStorageProperty.getName());
        return nacosStorageProperty.getName();
    }

    // @Transactional
    @Override
    public void deduct(String commodityCode, int count) {
        log.info("开始扣减库存");
        try {
            storageMapper.deduct(commodityCode, count);
        } catch (Exception e) {
            throw new RuntimeException("扣减库存失败，可能是库存不足！", e);
        }
        log.info("扣减库存成功");
    }
}
